<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%
  String ctxPath = request.getContextPath();
%>

<script language="JavaScript">

function doCancel(form) {
  form.action = "<c:url value="/ep/userTemplateChannelsView.do"/>";
  form.submit();
}

function doSave(form) {
  var orderValues = new Array();
  <c:forEach var="channel" items="${epUserTemplateChannelsView.map.channels}" varStatus="index">
	  var orderName = 'order_' + <c:out value="${channel.map.id}"/>;
      for (var i = 0; i < orderValues.length ; i++ )
      {
		  if (form[orderName].value == orderValues[i])
		  {
			alert("There are duplicate order number");
			return false;
		  }
      } 
 	  orderValues.push(form[orderName].value);
 </c:forEach>
  form.action = "<c:url value="/ep/userTemplateChannelsOrderSave.do"/>";
  form.submit();
}

function doResetAction(form) {
  form.reset();
}

function checkNumberOnly(e) {
  var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
  if (charCode > 31 && (charCode < 48 || charCode > 57)) {
    return false;
  }
  else {
    return true;
  }
}

<%@ include file="/mc/common/jsutils.jsp" %>

</script>

<%@include file="/mt/common/pickerPopupHelper.jsp" %>

<c:set var="removeImg">
<img src="<%= ctxPath %>/ep/images/action/icon_remove.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.remove" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.remove" bundle="ep.messages"/>">
</c:set>

<html-el:form action="/ep/userTemplateChannelsOrderSave.do">
<input type="hidden" name="userTemplateId" value="<c:out value='${epUserTemplateChannelsView.map.id}'/>"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
   <td valign="top" width="100%">
      <div class="pageTitle">
      <bean-el:message key="ep.user.template.view.page.title" bundle="ep.messages" arg0="${epUserTemplateChannelsView.map.name}"/>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>

      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="ep.user.template.channels.selected" bundle="ep.messages"/></span>
      </div>

      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
          <th id="Name" align="left" width="15%"><bean-el:message key="ep.header.name" bundle="ep.messages"/></th>
          <th id="ChannelPath" align="left" width="40%">Channel Path</th>
		  <th id="Description" align="left"><bean-el:message key="ep.header.description" bundle="ep.messages"/></th>
          <th id="Order" align="right" width="5%"><bean-el:message key="ep.header.order" bundle="ep.messages"/></th>
        </tr>
    <c:forEach var="channel" items="${epUserTemplateChannelsView.map.channels}" varStatus="index">
      <c:url var="removeUrl" value="/ep/userTemplateChannelsRemove.do">
        <c:param name="userTemplateId" value="${epUserTemplateChannelsView.map.id}"/>
        <c:param name="channelId" value="${channel.map.id}"/>
      </c:url>
      <c:choose>
        <c:when test="${(index.count + 1) % 2 == 0}">
          <tr class="listEven">
        </c:when>
        <c:otherwise>
          <tr class="listOdd">
        </c:otherwise>
      </c:choose>
            <input type="hidden" name="channelIds" value="<c:out value="${channel.map.id}"/>"/>
            <td headers="Name"><c:out value="${channel.map.name}"/></td>
            <td headers="ChannelPath"><c:out value="${channel.map.pathName}"/></td>
            <td headers="Description"><c:out value="${channel.map.description}"/></td>
			<td headers="Order">
              <input type="text" name="order_<c:out value="${channel.map.id}"/>"
                size="2" maxlength="2" onkeypress="return checkNumberOnly(event)"
                value="<c:if test="${channel.map.order != -1}"><c:out value="${channel.map.order}"/></c:if>"/>

            </td>
          </tr>
    </c:forEach>


<c:if test="${empty epUserTemplateChannelsView.map.channels}">
        <tr class="listOdd">
          <td align="center" colspan="5">
            <bean-el:message key="ep.user.template.channels.noFound" bundle="ep.messages"/>
          </td>
        </tr>
</c:if>
      </table>

<c:if test="${not empty epUserTemplateChannelsView.map.channels}">
        <div class="pageButtonWrap" align="right">
          <input type="button" name="resetBtn" class="pageButton"
            onclick="doResetAction(this.form);" value="<bean-el:message key='button.reset' bundle="ep.messages"/>">
          &nbsp;&nbsp;
          <input type="button" name="actionCancel" class="pageButton"
            onclick="doCancel(this.form);" value='<bean-el:message key="button.cancel" bundle="ep.messages"/>'>
          <input type="button" name="saveData" class="pageButton" 
			onclick="doSave(this.form);" value="<bean-el:message key='button.save' bundle="ep.messages" />">
        </div>
</c:if>

    </td>
  </tr>
</table>
</html-el:form>
